include('shared.lua');

SWEP.PrintName = "Build Gun";
SWEP.Slot = 1;
SWEP.SlotPos = 2;
SWEP.DrawAmmo = false;
SWEP.DrawCrosshair = false;

CreateClientConVar("buildgun_blocktype", 0, false, true);

p = nil;

function MakeCPanel()
	p = DermaMenu();
	for key, val in pairs(Blocks) do
		local sub = p:AddSubMenu(val.BlockName, function() RunConsoleCommand("buildgun_blocktype", key) end);
		sub:AddOption(val.Desc, function() RunConsoleCommand("buildgun_blocktype", key) end);
	end
	p:MakePopup();
	p:SetPos(surface.ScreenWidth()/2, surface.ScreenHeight()/2);
end

function ShowCPanel()
	//Create the cpanel
	if(p != nil) then
		if(p:IsValid()) then return; 
		else
			MakeCPanel();
		end
	else
		MakeCPanel();
	end
end
concommand.Add("weapon_buildgun_show_cpanel", ShowCPanel);

function SWEP:DrawHUD()
	if(self:GetNetworkedInt("isBuilding") == 0) then return; end
	
	
	local percent = self:GetNetworkedFloat("buildPercent");
	
	local height = ScrH()/4;
	
	draw.RoundedBox(5, 0, ScrH()/2, 25, height, Color(100, 100, 100, 255));
	height = height * percent;
	
	draw.RoundedBox(5, 0, ScrH()/2, 25, height, Color(0, 255, 0, 255));
	local p = math.Round(percent*100);
	draw.SimpleText(tostring(p) .. "%", "ScoreboardText", 5, ScrH()/2+5, Color(255, 255, 255, 255), 0, 1);
end